package com.xinyi;

/**
 * @desc:
 * @author: Shoko
 * @date: 2025/3/16
 */
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class TestUtil {

    // 通过配置文件的路径加载属性并返回类对象
    public static Class<?> getClassFromProperties(String propertyKey) throws Exception {
        // 假设配置文件路径为 "config.properties"
        Properties properties = new Properties();

        // 加载配置文件
        try (FileInputStream input = new FileInputStream("./config/config.properties")) {
            properties.load(input);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("Failed to load properties file");
        }

        // 获取配置文件中的类名
        String className = properties.getProperty(propertyKey);
        if (className == null) {
            throw new IllegalArgumentException("Property " + propertyKey + " not found in the configuration file.");
        }

        // 通过反射获取类对象并返回
        return Class.forName(className);
    }
}

